﻿// main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

import SecAssistPro

Window {
    id: root
    visible: true
    width: 800
    height: 600
    color: "transparent"
    flags: Qt.Window | Qt.FramelessWindowHint

    // 注册C++类
    property var windowsNative: WindowsNative {
        onWindowStateChanged: {
            if (state === 1) { // 最大化
                titleBar.maximizeVisible = false
                titleBar.restoreVisible = true
            } else { // 正常状态
                titleBar.maximizeVisible = true
                titleBar.restoreVisible = false
            }
        }
    }

    // 主内容区域
    Rectangle {
        anchors.fill: parent
        color: "#2D2D2D"
        border.color: "#1E1E1E"
        border.width: 1

        // 窗口阴影效果
        // layer.enabled: true
        // layer.effect: DropShadow {
        //     transparentBorder: true
        //     radius: 10
        //     samples: 16
        //     color: "#80000000"
        // }

        ColumnLayout {
            anchors.fill: parent
            spacing: 0

            // 自定义标题栏
            TitleBar {
                id: titleBar
                Layout.fillWidth: true
                Layout.preferredHeight: 40
                title: "自定义窗口"
                iconSource: "qrc:/res/image/favicon.ico.jpg"
                onCloseClicked: windowsNative.closeWindow(root)
                onMinimizeClicked: windowsNative.minimizeWindow(root)
                onMaximizeClicked: windowsNative.maximizeWindow(root)
                onRestoreClicked: windowsNative.restoreWindow(root)
                onDoubleClicked: {
                    if (windowsNative.isWindowMaximized(root)) {
                        windowsNative.restoreWindow(root)
                    } else {
                        windowsNative.maximizeWindow(root)
                    }
                }
            }

            // 主内容区
            Rectangle {
                Layout.fillWidth: true
                Layout.fillHeight: true
                color: "#252525"

                Label {
                    anchors.centerIn: parent
                    text: "应用程序内容区域"
                    color: "white"
                    font.pixelSize: 24
                }
            }
        }
    }

    // 边缘调整大小区域
    ResizeArea {
        window: root
        Component.onCompleted: {
            windowsNative = Qt.binding(function() { return root.windowsNative })
        }
    }

    // 初始化窗口
    Component.onCompleted: {
        windowsNative.setWindowFrame(root)
        windowsNative.setWindowTitleBar(root, 40)
    }
}
